package com.example.service.Impl;

import com.alicp.jetcache.Cache;
import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.CreateCache;
import com.example.domain.CaptchaCase;
import com.example.service.CaptchaCaseService;
import com.example.unlits.Unlit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class captchaCaseServiceImpl implements CaptchaCaseService {

    @Autowired
    private Unlit unlit;

    @CreateCache(name = "jetcache",expire = 3600,cacheType = CacheType.LOCAL)
    private Cache<String,String> jetcache;



    @Override
    public String sendCode(String tole){
        String code = unlit.encryptionCode(tole);
        jetcache.put(tole,code);
        return code;

    }

    @Override
    public Boolean captchaCode(CaptchaCase captchaCase) {
        System.out.println(captchaCase.getCode()+"service");
     return jetcache.get(captchaCase.getCode()).equals(captchaCase.getCode());
    }
}
